package com.thinkpadteam.edugra.fragmentsekolah;

import java.util.ArrayList;

import com.thinkpadteam.edugra.MainActivity;
import com.thinkpadteam.edugra.R;
import com.thinkpadteam.edugra.fragment.LessonConclution;
import com.thinkpadteam.edugra.game.GameMencocokkan;
import com.thinkpadteam.edugra.gridview.GridViewAdapter;
import com.thinkpadteam.edugra.gridview.ImageItem;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class MainSekolahFragment extends FragmentActivity {
	private ViewPager _mViewPager;
//	private ViewPagerAdapter _adapter;
//	int mCurrentPage;
	private ImageButton prev_btn, next_btn;
	private ImageButton play_btn, kesimpulan_btn, home_btn;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        /** Getting a reference to the ViewPager defined the layout file */        
        _mViewPager = (ViewPager) findViewById(R.id.pager);
        
        /** Getting fragment manager */
        FragmentManager fm = getSupportFragmentManager();
        
        /** Instantiating FragmentPagerAdapter */
        ViewPagerAdapterSekolah _adapter = new ViewPagerAdapterSekolah(fm);
        
        /** Setting the pagerAdapter to the pager object */
        _mViewPager.setAdapter(_adapter);
        
        _mViewPager.setCurrentItem(0);        
 	 
	   	 prev_btn = (ImageButton) findViewById(R.id.btn_prev);
	   	 next_btn = (ImageButton) findViewById(R.id.btn_next);   	   	 
	   	 play_btn = (ImageButton)findViewById(R.id.playbtn);
	   	 kesimpulan_btn = (ImageButton) findViewById(R.id.kesimpulan);
	   	 home_btn = (ImageButton) findViewById(R.id.home);
	   	 
	   	 RelativeLayout rl = (RelativeLayout)findViewById(R.id.menu);
	   	 rl.setBackgroundResource(R.drawable.bg_makan_v2);
	   	 
	   	 
//	   	Bundle data =	getIntent().getExtras();
//	   	mCurrentPage = data.getInt("current_page");
//	   	Log.d("cek mCur", "isi "+mCurrentPage);
	   	
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.layout.menu, menu);
        return true;
    }
    
    public void onClickBtn(View v){
    	Intent intent;
    	switch (v.getId()) {
		case R.id.btn_next:
			_mViewPager.setCurrentItem(_mViewPager.getCurrentItem() +1);
//			Toast.makeText(getApplicationContext(), "NEXTFRAGACT" + _mViewPager.getCurrentItem(), Toast.LENGTH_SHORT).show();
			break;
		case R.id.btn_prev:
			_mViewPager.setCurrentItem(_mViewPager.getCurrentItem() -1);
//			Toast.makeText(getApplicationContext(), "PREVFRAGACT", Toast.LENGTH_SHORT).show();
			break;
		case R.id.playbtn :
			intent = new Intent(MainSekolahFragment.this, GameMencocokkan.class);
			intent.putExtra("kategori", "makan");
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
			startActivity(intent);
			
			finish();
			break;
		case R.id.kesimpulan :
			intent = new Intent(this, LessonConclution.class);
			String uriextra = "";
			switch (_mViewPager.getCurrentItem()) {
			case 0:
				uriextra="android.resource://"+getPackageName()+"/"+R.raw.videopiring;
				break;
			case 1 :
				uriextra="android.resource://"+getPackageName()+"/"+R.raw.videopiring;
				break;
			case 2 :
				uriextra="android.resource://"+getPackageName()+"/"+R.raw.videomangkok;
				break;
			case 3 :
				uriextra="android.resource://"+getPackageName()+"/"+R.raw.videosendok;
				break;
			case 5:
				uriextra="android.resource://"+getPackageName()+"/"+R.raw.videogarpu;
				break;
			case 7 :
				uriextra="android.resource://"+getPackageName()+"/"+R.raw.videogelas;
				break;
			default:
				uriextra="android.resource://"+getPackageName()+"/"+R.raw.videomakan;
				break;
			}
//			if(_mViewPager.getCurrentItem() ==0){
//				
//			}else if(_mViewPager.getc){
//				uriextra="android.resource://"+getPackageName()+"/"+R.raw.v;
//			}
			intent.putExtra("urivideo", uriextra);							
			startActivity(intent);	
			break;
		case R.id.home : 
			intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			break;
		default:
			break;
		}
		
	}

}
